import request from '@/utils/requset'

//获取购物车数据
export const cartGetCartListService = () => {
  return request.get('/member/cart')
}
//添加购物车数据
type insertCartListParams = {
  skuId: string
  count: number
}
export const cartInsertCartListService = ({
  skuId,
  count
}: insertCartListParams) => {
  return request.post('/member/cart', { skuId, count })
}
//删除购物车数据
export const cartDeleteCartListService = (ids: Array<string>) => {
  return request.delete('/member/cart/', { data: { ids } })
}
//合并购物车数据
type cartMerageCartListParams = {
  skuId: string
  selected: string
  count: number
}
export const cartMergeCartListService = (
  goods: Array<cartMerageCartListParams>
) => {
  console.log(goods)
  return request.post('/member/cart/merge', goods)
}
//更新购物车数据
export const cartUpdateCartListService = (
  skuId: string,
  selected: string,
  count: number
) => {
  return request.put(`/member/cart/${skuId}`, { selected, count })
}

//全选/取消的更新
type cartUpdateCartListSelectedParams = {
  selected: boolean
  ids: Array<string>
}
export const cartUpdateCartListSelectedService = ({
  selected,
  ids
}: cartUpdateCartListSelectedParams) => {
  return request.put('/member/cart/selected', { selected, ids })
}
